package com.lxs;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;

public class CommonLocalDomains {
    public static void main(String[] args) {
        checkCommonDomains();
    }

    public static void checkCommonDomains() {
        List<String> commonDomains = Arrays.asList(
                "router", "gateway", "localhost",
                "nas", "server", "printer",
                "admin", "web", "ftp",
                "raspberrypi", "openwrt", "synology"
        );

        // 检查常见域名
        for (String domain : commonDomains) {
            checkDomain(domain);
            checkDomain(domain + ".local"); // mDNS
            checkDomain(domain + ".lan");   // 局域网域名
        }

        // 检查带数字后缀的常见设备
        for (int i = 1; i <= 5; i++) {
            checkDomain("printer" + i);
            checkDomain("printer" + i + ".local");
        }
    }

    private static void checkDomain(String domain) {
        try {
            InetAddress address = InetAddress.getByName(domain);
            if (!address.getHostAddress().equals(domain)) {
                System.out.println("发现域名: " + domain + " -> " + address.getHostAddress());
            }
        } catch (UnknownHostException e) {
            // 域名不存在，忽略
        }
    }
}
